<%  field, form_name, section_name, f, entity = hash[:field], hash[:form_name], hash[:section_name], hash[:form], hash[:entity] %>
<div class="fieldContainer fieldContainer<%= field["name"].capitalize %>">
  <% if field["type"] == "custom_text" %>
    <div class="customText">
      <%= raw t("#{form_name}.custom_text.#{field["name"]}")  %>
    </div>
  <% else %>
    <div class="fieldLabel fieldLabel<%= field["type"].capitalize %> fieldLabel<%= field["name"].capitalize %>">
      <%= f.label field["name"] %>
      <% if field["required"] %>
        <span class="required"><%= t "#{form_name}.required" %></span>
      <% end %>
    </div>
    <div class="fieldInput field<%= field["type"].capitalize %> field<%= field["name"].capitalize %>">
      <% case field["type"] %>
      <% when "text" then %>
        <%= f.text_field field["name"] %>
      <% when "textarea" then %>
        <%= f.text_area(field["name"], :cols => 100, :rows => 5, :class => "textareaRich") if field["rich"] %>
        <%= f.text_area(field["name"], :cols => 100, :rows => 5) unless field["rich"] %>
      <% when "password" then %>
        <%= f.password_field field["name"] %>
      <% when "radio_yn" then %>
        <% [true, false].each do |state| %>
          <%= f.radio_button field["name"], state, :class => "radio" %><span class="radioLabel"><%= field["custom"] ?
              t("#{form_name}.#{field["name"]}.radio_#{state}") : t("#{form_name}.radio_#{state}") %></span>
        <% end %>
      <% when "select" then %>
        <%= f.select(field["name"], get_availiable(form_name, section_name, field["name"]).collect {|item|
            [t("#{form_name}.#{field["name"]}.#{item}"), item]}, {:include_blank => t("#{form_name}.select_blank")}) %>
        <% if field["custom"] %>
          <div class="fieldCustom fieldCustomSelect formCustomSelect<%= field["type"].capitalize %>">
            <span class="fieldCustomLabel fieldCustomLabelSelect fieldCustomLabelSelect<%= field["type"].capitalize %>">
              <%= t("#{form_name}.#{field["name"]}.custom") %>
            </span>
            <%= f.text_field "#{field["name"]}_custom" %>
          </div>
        <% end %>
      <% when "select_num" then %>
        <%= f.select(field["name"], get_availiable(form_name, section_name, field["name"]).collect {|item|
            [item, item]}, {:include_blank => t("#{form_name}.select_blank")}) %>
        <% if field["custom"] %>
          <div class="fieldCustom fieldCustomSelect formCustomSelect<%= field["type"].capitalize %>">
            <span class="fieldCustomLabel fieldCustomLabelSelect fieldCustomLabelSelect<%= field["type"].capitalize %>">
              <%= t("#{form_name}.#{field["name"]}.custom") %>
            </span>
            <%= f.text_field "#{field["name"]}_custom" %>
          </div>
        <% end %>
      <% when "select_parent" then %>
        <%= f.select("#{field["name"]}_id", Kernel.const_get(field["name"].split("_").collect{|part| part.capitalize}.join).all.collect do |item|
            text = item.name
            if field["with_parent"]
              parent = item.send(field["with_parent"])
              text << " (#{parent.name}"
              if field["with_parent_parent"]
                parent_parent = parent.send(field["with_parent_parent"]) 
                text << ", #{parent_parent.name}"
              end
              text << ")"
            end
            [text, item.id] end, {:include_blank => t("#{form_name}.select_blank")}) %>
      <% when "checkboxes_db" then %>
        <%= hidden_field_tag "#{entity.class.to_s.downcase}[#{field["name"]}_ids][]" %>
        <% for item in Kernel.const_get(field["name"].split("_").collect{|part| part.capitalize}.join).all %>
          <div class="checkboxItem">
            <%= check_box_tag "#{entity.class.to_s.downcase}[#{field["name"]}_ids][]", item.id, entity.send("#{field["name"]}s").include?(item), :class => "checkbox" %>
            <span class="checkboxLabel"><%= item.name %></span>
          </div>
        <% end %>
      <% when "checkboxes" then %>
        <% for item in Kernel.const_get(field["name"].split("_").collect{|part| part.capitalize}.join).all %>
          <div class="checkboxItem">
            <%= check_box_tag "#{entity.class.to_s.downcase}[#{field["name"]}_ids][]", item.id, entity.send("#{field["name"]}s").include?(item), :class => "checkbox" %>
            <span class="checkboxLabel"><%= t("#{form_name}.#{field["name"]}.#{item.name}") %></span>
          </div>
        <% end %>
        <% if field["custom"] %>
          <div class="fieldCustom fieldCustomCheckboxes formCustomCheckboxes<%= field["type"].capitalize %>">
            <span class="fieldCustomLabel fieldCustomLabelCheckboxes fieldCustomLabelCheckboxes<%= field["type"].capitalize %>">
              <%= t("#{form_name}.#{field["name"]}.custom") %>
            </span>
            <%= f.text_field "#{field["name"]}_custom" %>
          </div>
        <% end %>
      <% when "date" then %>
        <%= date_select(form_name, field["name"], :start_year => 1900, :end_year => 2000, :order => [:day, :month, :year],
          :prompt => { :day => t("date.day"), :month => t("date.month"), :year => t("date.year") }) %>
      <% when "file" then %>
        <%= image_tag entity.send(field["name"]).url if entity.send(field["name"]) %>
        <%= f.file_field field["name"] %>
      <% when "captcha" then %>
        <%= raw recaptcha_tags :display => {:custom_translations => { :instructions_visual => t("captcha.instructions") }} %>
      <% end %>
      <% unless t("#{form_name}.helper.#{field["name"]}").empty? %>
        <div class="fieldHelper fieldHelper<%= field["type"].capitalize %>"><%= raw(t("#{form_name}.helper.#{field["name"]}")) %></div>
      <% end %>
    </div>
  <% end %>
</div>